package com.polaris.live.adapter

import android.view.View
import com.blankj.utilcode.util.ColorUtils
import com.polaris.live.R
import com.polaris.live.common.R.color
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterAwardProgressItemBinding
import com.polaris.live.resp.back_resp.LiveIndicatorRewardVo

/**
 * AwardProgressAdapter
 *
 * @author Created by 半仙 on 2024/1/18/018 20:34
 */
class AwardProgressAdapter(
    private val mWaitTime: Long,
) : BaseBindingAdapter<AdapterAwardProgressItemBinding, LiveIndicatorRewardVo>() {
    override fun convert(
        holder: VBViewHolder<AdapterAwardProgressItemBinding>,
        item: LiveIndicatorRewardVo,
    ) {
        holder.vb.apply {
            val position = holder.absoluteAdapterPosition
            if (position == 0) {
                itemView2.visibility = View.GONE
            } else {
                itemView2.visibility = View.VISIBLE
            }

            if (position == data.size - 1) {
                itemView.visibility = View.GONE
            } else {
                itemView.visibility = View.VISIBLE
            }

            if (mWaitTime >= item.liveTime) {
                llTitle.alpha = 0.4f
                tvTime.alpha = 0.4f
                llTitle.setBackgroundResource(R.drawable.r8_anchor_progress_alpha)
                itemAnchorOval.setBackgroundResource(R.drawable.oval_back_anchor)
                ivTitleChestImg.setImageResource(R.drawable.anchor_progress_open_img)
            } else {
                llTitle.alpha = 1f
                tvTime.alpha = 1f
                llTitle.setBackgroundResource(R.drawable.r8_back_f8f9fa)
                itemAnchorOval.setBackgroundResource(R.drawable.oval_back_anchor_gray)
                ivTitleChestImg.setImageResource(R.drawable.anchor_progress_close_img)
            }

            val nextPosition = position + 1
            val lastPosition = position - 1

            if (nextPosition < data.size && mWaitTime >= data[nextPosition].liveTime) {
                itemView.setBackgroundColor(ColorUtils.getColor(color.color_FA3A9E))
            } else {
                itemView.setBackgroundColor(ColorUtils.getColor(R.color.color_d8d8d8))
            }

            if (position != 0 && mWaitTime >= data[lastPosition].liveTime && mWaitTime >= item.liveTime) {
                itemView2.setBackgroundColor(ColorUtils.getColor(color.color_FA3A9E))
            } else {
                itemView2.setBackgroundColor(ColorUtils.getColor(R.color.color_d8d8d8))
            }

            tvTime.text = item.name
        }
    }
}